import json

import allure
import jsonpath
import requests


class ApiKey():
    @allure.step("发送get请求")
    def get(self,url, params=None, **kwargs):
        return requests.get(url=url, params=params, **kwargs)
    @allure.step("发送post请求")
    def post(self,url, data, **kwargs):
        return requests.post(url=url, json=data, **kwargs)
    @allure.step("获取指定响应数据")
    def get_text(self,response,key):
        dict_data=json.loads(response)
        value_list = jsonpath.jsonpath(dict_data,key)
        return value_list[0]
# if __name__ == '__main__':
#     data={
#         "accounts":'hu2374145',
#         "pwd": "hu2374145",
#         "type":"username"
#     }
#     headers={
#         "content-type":"application/json"
#     }
#     params={
#         "application":"app",
#         "application_client_type":"weixin"
#     }
#     ak=ApiKey()
#     res = ak.post(url="http://shop-xo.hctestedu.com/index.php?s=api/user/login",params=params,data=data,headers=headers)
#     print(res.text)
#     print(ak.get_text(res.text,"$..token"))